<?php

namespace Home\Controller;

use Think\Controller;

class ActivityController extends HomeController {
    /**
     * 余额流水
     * @param $amount int 变动金额
     * @param $detail string 明细
     * @param $act string 操作
     * @author Scor 2015-10-10
     */
    public function amountFlow($amount,$detail,$act){
        $userid = session('userid');
        $map['id']=$userid;
        $res=M('buyers')->where($map)->find();
        $amount_arr["change_amount"]=$amount;
        $amount_arr["before_amount"]=$res["amount"];
        if($act=="incre"){
            $amount_arr["after_amount"]=$res["amount"]+$amount;
            $act="获得";
        }else{
            $act="消费";
            $amount_arr["after_amount"]=$res["amount"]-$amount;
        }
        $amount_arr["action"]=($amount_arr["after_amount"]>$amount_arr["before_amount"])?1:-1;
        $amount_arr["detail"]=$detail.$act.$amount;
        $amount_arr["uid"]=$userid;
        $amount_arr["createtime"]=time();
        if($amount>0){
            D("amount_flow")->add($amount_arr);
        }
    }
    public function isCart($pid){
        $data['pid']=$pid;
        $data['uid']=session('userid');
        $flagres=D('cart')->where($data)->select();
        if(count($flagres)==0){
            $iscartflag=false;
        }else{
            $iscartflag=true;
        }
        return $iscartflag;
    }
}
